package Day2025_03_02;

public class LeetCode14 {
    public String longestCommonPrefix(String[] strs) {
        int len =  strs[0].length();
        StringBuffer result = new StringBuffer();
        for (String str : strs) len = Math.min(len, str.length());
        int i = 0;
        while (i < len) {
            int[] hash = new int[26];
            for (String str : strs) {
                char ch = str.charAt(i);
                hash[ch - 'a']++;
            }
            char ch = strs[0].charAt(i);
            if (hash[ch - 'a'] != strs.length) break;
            result.append(ch);
            i++;
        }
        return result.toString();
    }
}
